package com.hdu.dwh.vos;

import java.util.Set;

import org.springframework.beans.BeanUtils;

import com.hdu.dwh.pojos.cube_pojos.Cuboid;
import com.hdu.dwh.pojos.cube_pojos.CuboidDimension;

import lombok.Data;

@Data
public class CuboidVo {
    private String tag;
    private Integer id;
    private Integer level;
    private Integer tableId;
    private Boolean isStored;
    private Set<CuboidDimension> dimensions;
    private Set<InnerCuboidVo> nextLevelCuboids;
    private Set<InnerCuboidVo> preLevelCuboids;
    private String createdBy;
    public void setDimensions(Set<? extends CuboidDimension> _dimensions) {
        Set<CuboidDimension> dims = _dimensions.stream().map(dim -> {
            CuboidDimension dimCopy = new CuboidDimension();
            BeanUtils.copyProperties(dim, dimCopy);
            return dimCopy;
        }).collect(java.util.stream.Collectors.toSet());
        
        this.dimensions = dims;
    }

    public void setNextLevelCuboids(Set<? extends Cuboid> _nextLevelCuboids) {
        Set<InnerCuboidVo> nextLevelCuboidVos = _nextLevelCuboids.stream().map(cuboid -> {
            InnerCuboidVo cuboidVo = new InnerCuboidVo();
            InnerCuboidVo.copyProperties(cuboid, cuboidVo);
            return cuboidVo;
        }).collect(java.util.stream.Collectors.toSet());
        this.nextLevelCuboids = nextLevelCuboidVos;
    }

    public void setPreLevelCuboids(Set<? extends Cuboid> _preLevelCuboids) {
        Set<InnerCuboidVo> preLevelCuboidVos = _preLevelCuboids.stream().map(cuboid -> {
            InnerCuboidVo cuboidVo = new InnerCuboidVo();
            InnerCuboidVo.copyProperties(cuboid, cuboidVo);
            return cuboidVo;
        }).collect(java.util.stream.Collectors.toSet());
        this.preLevelCuboids = preLevelCuboidVos;
    }
    
}

@Data
class InnerCuboidVo {
    public static void copyProperties(Cuboid cuboid, InnerCuboidVo cuboidVo) {
        cuboidVo.setId(cuboid.getId());
        cuboidVo.setTag(cuboid.getTag());
        cuboidVo.setLevel(cuboid.getLevel());
        Set<CuboidDimension> dimensions = cuboid.getDimensions().stream().map(dim -> {
            CuboidDimension dimCopy = new CuboidDimension();
            BeanUtils.copyProperties(dim, dimCopy);
            return dimCopy;
        }).collect(java.util.stream.Collectors.toSet());
        cuboidVo.setDimensions(dimensions);

    }
    private Integer id;
    private String tag;
    private Integer level;
    private Set<CuboidDimension> dimensions;
}